// pages/home/index.js
const { getMiaoSha,getGropData } =  require("../../api/index")

Page({
  ClickLive(){
    wx.navigateTo({
      url: '../Live/index',
    })
  },
  /*
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    swiperList: ['../../static/1.png','../../static/2.png'],
    indicatorDots: true,
    vertical: true,
    autoplay: true,
    interval: 3000,
    duration: 500,
    navList:[
      {
        title:"商品分类",
        bgcolor:'#FF7578',
        img:"../../static/分类.png"
      },
      {
        title:"领优惠券",
        bgcolor:'#935BFE',
        img:"../../static/优惠券.png"
      },
      {
        title:"行业资讯",
        bgcolor:'#FA9813',
        img:"../../static/情趣行业资讯.png"
      },
      {
        title:"我要签到",
        bgcolor:'#FD9263',
        img:"../../static/签到.png"
      },
      {
        title:"我的收藏",
        bgcolor:'#1AA8FB',
        img:"../../static/收藏.png"
      },
      {
        title:"拼团活动",
        bgcolor:'#FA9813',
        img:"../../static/拼团.png"
      },
      {
        title:"秒杀活动",
        bgcolor:'#FD9263',
        img:"../../static/秒杀.png"
      },
      {
        title:"砍价活动",
        bgcolor:'#935BFE',
        img:"../../static/砍价.png"
      },
      {
        title:"地址管理",
        bgcolor:'#1AA8FB',
        img:"../../static/地址管理.png"
      },
      {
        title:"订单管理",
        bgcolor:'#FF7578',
        img:"../../static/订单管理 (1).png"
      },
    ],
    tabOne:[
      "首页","每日新品","热门推荐","家用电器","美妆个护"
    ],
    tabTwo:[
      "促销商品","精品推荐","热门榜单","首发新品","美妆个护"
    ],
    active:0,
    swiperdemo:[
      "../../static/1.jpg"
    ],
    seckillList:[],
    gropList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    /**
     * 获取当前设备的宽高
     */
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
    
    // 获取秒杀数据
    getMiaoSha().then(res => {
      console.log(res);
      that.setData  ({
        seckillList:res.data.data
      })
    })
    // 获取拼团数据
    getGropData().then(res => {
      console.log(res);
      that.setData  ({
        gropList:res.data.data
      })
    })

   
  },
  swichNav: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },

  tabTwo:function(e){
    var that = this;
    if (this.data.active === e.target.dataset.active) {
      return false;
    } else {
      that.setData({
        active: e.target.dataset.active
      })
    }
  },

   // 跳详情
   toInfo(item){
     const id = item.currentTarget.dataset.id
     // console.log(item)
     wx.navigateTo({
      url:'../../pages/info/index?id=' + id,
     })
   },

  bindChange: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  // // 获取用户信息
  // getUserInfo() {
  //   const appId = wx.getAccountInfoSync().miniProgram.appId
  //   const secret = '69774f8e6d6ca86201c75d021a3c4b54'
  //   wx.login({
  //     success: (res) => {
  //       const code = res.code
  //       wx.request({
  //         url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appId + '&secret=' + secret + '&js_code=' + code + '&grant_type=authorization_code',
  //         header: {
  //           'content-type': 'json'
  //         },
  //         success: function (res) {
  //           var openid = res.data.openid //返回openid
  //           console.log('openid为' + openid);
  //         }
  //       })
  //     }
  //   })
  // },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})